package org.hackystat.devcathlon.ui.page.profile;

import org.apache.wicket.behavior.SimpleAttributeModifier;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.hackystat.devcathlon.engine.profile.Profile;
import org.hackystat.devcathlon.ui.DevcathlonSession;
import org.hackystat.devcathlon.ui.page.DevcathlonBasePage;

/**
 * Implements the main Profile page, which provides a summary of this user.  
 * @author Anthony Du, Philip Johnson
 *
 */
public class ProfilePage extends DevcathlonBasePage {
  /** Support serialization. */
  private static final long serialVersionUID = 1L;
  /** The welcome message. */
  protected String welcomeMessage = "Welcome home!";
  
  /**
   * Creates the Profile page.  
   * This page and its subpages contain information about this specific user.  
   */
  public ProfilePage () {
    /** Profile session. */
    ProfileSession session = DevcathlonSession.get().getProfileSession();
    /** The session state for this page. */
    Profile profile = session.getProfile();
    
    // Set welcome message.
    if (("".equals(profile.getFirstName())
        || "".equals(profile.getLastName()))
        && !("".equals(profile.getScreenName()))) {
      welcomeMessage = "Welcome home " + profile.getScreenName() + "!";
    }
    else if (!("".equals(profile.getFullName()))) {
      welcomeMessage = "Welcome home " + profile.getFullName() + "!";
    }
    
    // Set the body class attribute to section-1 so that the menubar is correct.
    add(new WebMarkupContainer("body") { 
      private static final long serialVersionUID = 1L;
      @Override
      public boolean isTransparentResolver() { 
        return true; 
        } 
      @Override
      protected void onComponentTag(ComponentTag tag) { 
        tag.put("class", "thrColElsHdr section-1"); 
      }
    });
    // User's fullname
    add(new Label("welcomeMessage", welcomeMessage));
    // Profile panels
    add(new ProfilePanel("profilePanel"));
    // Make the tab corresponding to this page bold.
    session.setProfile(DevcathlonSession.get().getEmail());
    get("ProfileLink").add(new SimpleAttributeModifier("class", "selected"));
  }
}

